package com.contactmgr.listadapter;


import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.contactmgr.R;
import com.contactmgr.logObjects.Sms;
import com.contactmgr.utils.DateUtils;

public class SmsListAdapter extends ArrayAdapter<Sms> {
	private List<Sms> sms;
	int resourceid;
	Context context;

	public SmsListAdapter(Context context, int textViewResourceId, List<Sms> Sms) {
		super(context, textViewResourceId, Sms);
		this.context = context;
		this.sms = Sms;
		this.resourceid = textViewResourceId;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup viewGroup) {
		Sms curSms = sms.get(position);
		if (null == convertView) {
			// inflate xml layout
			LayoutInflater inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflator.inflate(resourceid, null);
		}
		TextView fromtTo= (TextView) convertView.findViewById(R.id.smsfromToNameNumber);
		TextView date= (TextView) convertView.findViewById(R.id.dateSms);
//		if(curSms.getSmsType().equals(Sms.TYPE.RECEIVED)){
//			fromtTo.setText("From :"+curSms.getFromTo());
//		} else {
//			fromtTo.setText("To :"+curSms.getFromTo());
//		}
		fromtTo.setText(curSms.getFromTo()+curSms.getPerson());
		date.setText("Date/Time :"+DateUtils.getFormattedDateOfEpoch(curSms.getDate()));
		return convertView;
	}


}
